// background.js
const targetUrl = "https://fe-static.xhscdn.com/formula-static/xhs-pc-web/public/resource/js/vendor-dynamic.487a47f1.js";
const replacementUrl = "https://scriptcat.org/lib/3492/1.0.1/xhs_xs_xcommon.js";
// 在扩展安装时添加规则
chrome.runtime.onInstalled.addListener(() => {
  chrome.declarativeNetRequest.updateDynamicRules({
    addRules: [
      {
        id: 1,
        priority: 1,
        action: {
          type: "redirect",
          redirect: { url: replacementUrl }
        },
        condition: {
          urlFilter: targetUrl,
          resourceTypes: ["script"] // 仅拦截脚本资源
        }
      }
    ],
    removeRuleIds: [1] // 确保规则唯一性
  });
});